<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title><%= title %> - WDShare</title>
<meta name="keywords" content="<%= title %>" />
<meta name="description" content="<%= title %>" />
<% include etc/htmlhead.ejs %>
</head>

<body>
<% include etc/head.ejs %>
<% include etc/article-head-ad.ejs %>
<%
  var showPageSize = 5;
      item_sum = +pages.sum,
      page_current = +pages.page,
      page_size = pages.pagesize,
      page_sum = Math.ceil(item_sum/page_size),
      pathname = pages.pathname,
      beforeOmit = false,
      afterOmit = false;


  function getPageHTML(c) {
    var _html = '';
    if ( i+1 == +page_current ) {
      _html += '<span class="pages-current">'+ c +'</span>';
    } else {
      _html += '<a href="'+ pathname +'?page='+ c +'&pagesize='+ page_size +'">'+ c +'</a>';
    }
    return _html;
  };
%>
<div class="article-list">
  <div class="maxWidth module">
    <h2 class="module-title">
      <% if ( title != "精彩文章" ) { %>
      <a href="/article">TAG</a> &gt; 
      <% } %>
      <%= title %>
    </h2>
    <div class="article-list-con">
      <% result.forEach(function(article){ %>
      <%
        var tou = false,
            hot = false,
            _strong = false,
            types = [],
            model = '';
        if ( article.diyType ) {
          types = article.diyType.split(",");
        }
        for ( var i=0; i<types.length; i++ ) {
          if ( parseInt(types[i]) === 1 ) {
            tou = true;
          }
          if ( parseInt(types[i]) === 2 ) {
            hot = true;
          }
          if ( parseInt(types[i]) === 3 ) {
            _strong = true;
          }
        }

        if ( article.type == 1 ) {
          model = "article";
        } else if ( article.type == 2 ) {
          model = "project";
        } else if ( article.type == 3 ) {
          model = "job";
        }
      %>
      <div class="article-item">
        <% if ( !article.user ) { %>
        <div class="article-item-user"><img src="/static/users/default-face.png" title="该用户消失了" /></a></div>
        <% } else { %>
        <div class="article-item-user"><a href="/user/<%= article.userId %>" title="发布者：<%= article.user %>"><img src="/user/face/<%= article.userId %>" /></a></div>
        <% } %>
        <div class="article-item-text">
          <h3 class="article-item-title">
            <a href="/<%=model%>/<%= article._id %>" title="<%= article.title %>"<% if ( article.linkUrl ) { %> target="_blank"<% } %>><em style="<% if ( article.color ) { %>color:<%= article.color %>;<% } %> font-weight:<%= _strong ? "bold" : "normal" %>;"><%= article.title %></em><% if ( article.linkUrl ) { %><span class="link-url">[外链]</span><% } %></a>
          </h3>
          <div class="article-item-type">
            <span class="article-item-date">时间：<%= moment(article.editDate).format('YYYY-MM-DD HH:mm:ss') %></span>
            <span class="article-item-click">点击：<%= article.click ? article.click : 0 %></span>
            <% if ( !article.linkUrl ) { %>
            <span class="article-item-comment">赞：<%= article.zan ? article.zan : 0 %></span>
            <% } %>
          </div>
        </div>
      </div>
      <% }) %>
    </div>

    <% if ( page_sum > 1 ) { %>
    <div class="pages">
      <div class="pages-con">
        <% if ( page_current != 1 ) { %>
        <a href="<%=pathname%>?page=<%=+page_current-1%>&pagesize=<%=page_size%>" class="pages-prev">上一页</a>
        <% } else { %>
        <span class="pages-prev pages-dead">上一页</span>
        <% } %>
        <% for( var i=0; i<page_sum; i++ ) { %>
          
          <% if ( i == 0 || i == page_sum-1 ) { %>
            <%- getPageHTML(i+1) %>
            <% continue %>
          <% } %>

          <% if ( page_current-Math.floor(showPageSize/2) > 2 && !beforeOmit ) { %>
            <span class="pages-omit">...</span>
            <% beforeOmit = true %>
          <% } %>

          <% if ( i+1 > page_current+Math.floor(showPageSize/2) ) { %>
            <% if ( !afterOmit ) { %>
              <span class="pages-omit">...</span>
              <% afterOmit = true %>
            <% } %>
            <% continue %>
          <% } %>

          <% if ( i+1 >= page_current-Math.floor(showPageSize/2) ) { %>
            <%- getPageHTML(i+1) %>
            <% continue %>
          <% } %>

        <% } %>
        <!-- <span class="pages-omit">...</span> -->
        <% if ( page_current >= page_sum ) { %>
        <span class="pages-next pages-dead">下一页</span>
        <% } else { %>
        <a href="<%=pathname%>?page=<%=+page_current+1%>&pagesize=<%=page_size%>" class="pages-next">下一页</a>
        <% } %>
      </div>
    </div>
    <% } %>
  </div>
</div>

<% include etc/foot.ejs %>
</body>
</html>